let obj = {
    a: {
        b: {
            c: {
                d: 1
            }
        }
    }
};

const getValue = (originObj, keyPath) => {
    let keys = keyPath.split('.'),
        index = 0,
        result;
    const recur = (obj) => {
        if (index >= keys.length) return;
        result = obj[keys[index++]];
        if (result === null || typeof result !== "object") return;
        recur(result);
    };
    recur(originObj);
    return result;
};

let res1 = getValue(obj, 'a.b.c.d');
console.log(res1);

let res2 = getValue(obj, 'a.b');
console.log(res2);